package com.hongxun.modules.bss.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.bss.dao.DMaterialOldDao;
import com.hongxun.modules.bss.entity.DMaterialOldEntity;
import com.hongxun.modules.bss.service.DMaterialOldService;



@Service("dMaterialOldService")
public class DMaterialOldServiceImpl implements DMaterialOldService {
	@Autowired
	private DMaterialOldDao dMaterialOldDao;

	@Override
	public DMaterialOldEntity queryObject(String guid){
		return dMaterialOldDao.queryObject(guid);
	}
	
	@Override
	public List<DMaterialOldEntity> queryList(Map<String, Object> map){
		return dMaterialOldDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return dMaterialOldDao.queryTotal(map);
	}
	
	@Override
	public void save(DMaterialOldEntity dMaterialOld){
        if(dMaterialOld.getGuid()==null||dMaterialOld.getGuid().equals("")) {

		    dMaterialOld.setGuid(UUID.randomUUID().toString());
        }
		dMaterialOldDao.save(dMaterialOld);
	}
	
	@Override
	public void update(DMaterialOldEntity dMaterialOld){
		dMaterialOldDao.update(dMaterialOld);
	}
	
	@Override
	public void delete(String guid){
		dMaterialOldDao.delete(guid);
	}
	
	@Override
	public void deleteBatch(String[] guids){
		dMaterialOldDao.deleteBatch(guids);
	}

	@Override
	public void insertOrReplaceOrDelete(List<DMaterialOldEntity> entities) {
		for (DMaterialOldEntity d : entities) {
			if (d.getMBDatastate().equals("删除")) {
				dMaterialOldDao.delete(d.getGuid());
			} else {
				DMaterialOldEntity dMaterialOldEntity = dMaterialOldDao.queryObject(d.getGuid());
				if (dMaterialOldEntity == null) {
					dMaterialOldDao.save(d);
				} else {
					dMaterialOldDao.update(d);
				}
			}
		}
	}
}
